// Machine generated IDispatch wrapper class(es) created with Add Class from Typelib Wizard

//#import "C:\\Windows\\SysWOW64\\vbscript.dll" no_namespace
// CRegExp wrapper class
#pragma once

class CRegExp : public COleDispatchDriver
{
public:
	CRegExp(){} // Calls COleDispatchDriver default constructor
	CRegExp(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
	CRegExp(const CRegExp& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

	// Attributes
public:

	// Operations
public:


	// IRegExp methods
public:
	CString get_Pattern()
	{
		CString result;
		InvokeHelper(0x2711, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
		return result;
	}
	void put_Pattern(LPCTSTR newValue)
	{
		static BYTE parms[] = VTS_BSTR ;
		InvokeHelper(0x2711, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
	}
	BOOL get_IgnoreCase()
	{
		BOOL result;
		InvokeHelper(0x2712, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
		return result;
	}
	void put_IgnoreCase(BOOL newValue)
	{
		static BYTE parms[] = VTS_BOOL ;
		InvokeHelper(0x2712, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
	}
	BOOL get_Global()
	{
		BOOL result;
		InvokeHelper(0x2713, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
		return result;
	}
	void put_Global(BOOL newValue)
	{
		static BYTE parms[] = VTS_BOOL ;
		InvokeHelper(0x2713, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
	}
	LPDISPATCH Execute(LPCTSTR sourceString)
	{
		LPDISPATCH result;
		static BYTE parms[] = VTS_BSTR ;
		InvokeHelper(0x2714, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, parms, sourceString);
		return result;
	}
	BOOL Test(LPCTSTR sourceString)
	{
		BOOL result;
		static BYTE parms[] = VTS_BSTR ;
		InvokeHelper(0x2715, DISPATCH_METHOD, VT_BOOL, (void*)&result, parms, sourceString);
		return result;
	}
	CString Replace(LPCTSTR sourceString, LPCTSTR replaceString)
	{
		CString result;
		static BYTE parms[] = VTS_BSTR VTS_BSTR ;
		InvokeHelper(0x2716, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms, sourceString, replaceString);
		return result;
	}
	CString GetFirstMatchGroup(LPCTSTR sourceString)
	{
		if (!Test(sourceString))return _T("");
		CString result;
		LPDISPATCH matchesDispatch = Execute(sourceString);
		if (matchesDispatch)
		{
			COleDispatchDriver matchesDriver(matchesDispatch);
			LPDISPATCH matchItemDispatch = NULL;

			// Using DISPATCH_PROPERTYGET to access the first match
			static BYTE indexParm[] = VTS_I4;
			long index = 0;
			matchesDriver.InvokeHelper(0x0, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&matchItemDispatch, indexParm, index);  // Get the first match

			if (matchItemDispatch)
			{
				COleDispatchDriver matchDriver(matchItemDispatch);
				LPDISPATCH subMatchesDispatch = NULL;

				// Obtain the DISPID for SubMatches using GetIDsOfNames
				OLECHAR* szMember = L"SubMatches";
				DISPID dispidSubMatches;
				HRESULT hr = matchDriver.m_lpDispatch->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispidSubMatches);

				if (SUCCEEDED(hr))
				{
					matchDriver.InvokeHelper(dispidSubMatches, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&subMatchesDispatch, NULL);  // Get submatches

					if (subMatchesDispatch)
					{
						COleDispatchDriver subMatchesDriver(subMatchesDispatch);
						CString firstGroup;
						subMatchesDriver.InvokeHelper(0x0, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&firstGroup, indexParm, index);  // Get the first captured group ($1)
						result = firstGroup;
					}
				}
				else
				{
					AfxMessageBox(_T("Failed to get DISPID for SubMatches"));
				}
			}
		}
		return result;
	}

	// IRegExp properties
public:

};
